package com.wuliu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuliu.common.core.domain.ApiResult;
import com.wuliu.common.core.domain.entity.BasCust;
import com.wuliu.common.utils.SecurityUtils;
import com.wuliu.system.mapper.BasCustUserMapper;
import com.wuliu.system.service.applet.IBasCustUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.domain.BasCustUser;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 客户专属业务员Controller
 *
 * @author realue
 * @date 2023-11-01
 */
@Api(tags = {"专属业务员控制器"})
@RestController
@RequestMapping("/applet/user")
public class BasCustUserController extends BaseController {
    @Resource
    private IBasCustUserService basCustUserService;
    @Resource
    private BasCustUserMapper basCustUserMapper;

    /**
     * 查询客户专属业务员列表
     */
    @ApiOperation(value = "查询专属业务员")
    @GetMapping("/list")
    public ApiResult<List<BasCustUser>> list() {
        BasCust basCust = SecurityUtils.getBasCust();
        List<BasCustUser> list = basCustUserMapper.selectList(new LambdaQueryWrapper<BasCustUser>()
                .eq(BasCustUser::getSysAccount, basCust.getSysAccount())
                .eq(BasCustUser::getCustId, basCust.getId()));
        return ApiResult.success(list);
    }


    /**
     * 新增客户专属业务员
     */
    @ApiOperation(value = "新增专属业务员")
    @ApiImplicitParam(name = "userNo", value = "业务员编号", dataType = "String", paramType = "query")
    @PostMapping
    public ApiResult<Integer> add(String userNo) {
        return ApiResult.success(basCustUserService.insertBasCustUser(userNo));
    }


    /**
     * 删除客户专属业务员
     */
    @ApiOperation(value = "删除专属业务员")
    @DeleteMapping("/{ids}")
    public ApiResult<Integer> remove(@PathVariable Long[] ids) {
        return ApiResult.success(basCustUserService.deleteBasCustUserByIds(ids));
    }
}
